package at.jku.pervasive.recognition;

import at.jku.pervasive.Position;

public class SimpleGestureDetector implements GestureDetector
{

	@Override
	public GestureType getRecognizedGesture(Position left, Position reference, Position right)
	{
		// extract gestures depending on characteristics of the positions; begin
		// with calculating the gesture characteristics
		GestureCharacteristics gC = new GestureCharacteristics(left, reference, right);

		// left and reference position are lower than the right
		if (gC.leftIsLowerThanRight() && gC.refIsLowerThanRight())
		{
			// left and reference are on the same height
			if (gC.refHasEqualHeightToLeft())
				return GestureType.LSRU;
			// left is lower than the reference
			else if (gC.leftIsLowerThanRef())
				return GestureType.LDRU;
		}
		// same as the IF before, just for the mirrored case
		else if (gC.rightIsLowerThanLeft() && gC.refIsLowerThanLeft())
		{
			if (gC.refHasEqualHeightToRight())
				return GestureType.LURS;
			else if (gC.rightIsLowerThanRef())
				return GestureType.LURD;
		}
		// left, reference and right are on the same height
		else if (gC.refHasEqualHeightToLeft() && gC.refHasEqualHeightToRight())
		{
			// both arms are stretched to the side
			if (gC.angleIs180())
				return GestureType.LSRS180;
			// both arms are stretched at right angles
			else if (gC.angleIs90())
				return GestureType.LSRS90;
			// both arms are stretched to the same direction
			else if (gC.angleIs0())
				return GestureType.LSRS0;
		}

		// the next two ELSE IF check for the case that one arm is down and one
		// arm is stretched on the same height as the reference point
		else if (gC.rightIsLowerThanRef() && gC.refHasEqualHeightToLeft())
		{
			return GestureType.LSRD;
		}
		else if (gC.leftIsLowerThanRef() && gC.refHasEqualHeightToRight())
		{
			return GestureType.LDRS;
		}

		// this case checks for both arms stretched up in the air
		else if (gC.refIsLowerThanLeft() && gC.refIsLowerThanRight() && gC.leftHasEqualHeightToRight())
		{
			return GestureType.LURU;
		}
		// this case checks for both arms down
		else if (gC.leftIsLowerThanRef() && gC.rightIsLowerThanRef())
		{
			return GestureType.LDRD;
		}

		// no gesture could be extracted out of the characteristics
		return GestureType.NONE;
	}

}
